package image;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;

import javax.imageio.ImageIO;

import process.*;
/*! a kamera osztalya */
public class CameraBuff {
	
	private int fps;
	private int imgIndex; // ez csak amig nincs kamera es filebol jonnek a kepek (asszem)
	private Queue<OwnImage> imagesBuff;
	//! Konstruktor
	/*!
	  \param fps int
	*/
	public CameraBuff(int fps){
		this.fps = fps;
		imgIndex = 0;
		imagesBuff = new LinkedList<OwnImage>();
	}
	
	//! kepek beolvasa
	/*!
	  \param path string
	*/
	private void populate() throws IOException{
		for(int i = imgIndex+88; i < imgIndex + 108 ;i++)
			imagesBuff.offer(new OwnImage(ImageIO.read(new File("video/frame"+i+".jpg")),1000*imgIndex/fps));
		imgIndex += 20;	
	}
	
	
	//! kepek listajanak visszateritese
	/*!
	  \return kepek listaja
	*/
	public OwnImage getImage(){
		File file = new File("video/labda.jpg");
		BufferedImage kep = null;
		try{
			kep=ImageIO.read(file);
			
		}catch(IOException e){
			System.err.println("nincs kep");
		}
	return new OwnImage(kep,0);
		/*
		if(imagesBuff.isEmpty())
			try {
				populate();
				return getImage();
			} catch (IOException e) {
				// TODO Auto-generated catch block				
				if(imagesBuff.isEmpty())
					return null;
				return getImage();
			}
		
		return imagesBuff.poll();
		*/
	}
}
